package com.gduf.lsm.service;


import cn.hutool.core.util.ObjectUtil;
import com.gduf.lsm.common.enums.ResultCodeEnum;
import com.gduf.lsm.entity.Feedback;
import com.gduf.lsm.exception.CustomException;
import com.gduf.lsm.mapper.FeedbackMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 反馈信息表业务处理
 **/
@Service
public class FeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    /**
     * 新增
     * @param feedback
     */
    public void add(Feedback feedback) {
        //判断公告标题、内容和通知对象不为空才可以插入
        if(ObjectUtil.isEmpty(feedback.getStatus())||ObjectUtil.isEmpty(feedback.getContent())){
            throw new CustomException(ResultCodeEnum.FEEDBACK_NULL_ERROR);
        }
        feedbackMapper.insert(feedback);
    }

    /**
     * 删除
     * @param id
     */
    public void deleteById(Integer id) {
        feedbackMapper.deleteById(id);
    }

    /**
     * 批量删除
     * @param ids
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            feedbackMapper.deleteById(id);
        }
    }

    /**
     * 修改
     * @param feedback
     */
    public void updateById(Feedback feedback) {
        feedbackMapper.updateById(feedback);
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    public Feedback selectById(Integer id) {
        return feedbackMapper.selectById(id);
    }

    /**
     * 查询所有
     * @param feedback
     * @return
     */
    public List<Feedback> selectAll(Feedback feedback) {
        return feedbackMapper.selectAll(feedback);
    }

    /**
     * 分页查询
     * @param feedback
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<Feedback> selectPage(Feedback feedback, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Feedback> list = feedbackMapper.selectAll(feedback);
        return PageInfo.of(list);
    }

}